<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主要人员</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
	<form id="cust_cst_corp_team_form">
		<div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
			<div class="fieldBox col_50">
				<div class="label">成员类型</div>
				<div class="field">
					<select name="mTypCd" id="mTypCd" data-value=""
						validate="{required:true, select: true}">
						<c:forEach items="${searchSelectMTypCdList }" var="kv" begin="0"
							step="1" varStatus="status">
							<c:if test="${status.index == 0}">
								<option value="${kv.key }" checked>${kv.value }</option>
							</c:if>
							<c:if test="${status.index != 0}">
								<option value="${kv.key }">${kv.value }</option>
							</c:if>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">姓名</div>
				<div class="field">
					<input name="mNm" id="mNm" type="text" class="ui-textbox" value=""
						validate="{required:true,nmcharacter:true,maxlength:20}">
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">性别</div>
				<div class="field">
					<c:forEach items="${searchSelectGenderCdList }" var="kv" begin="0"
						step="1" varStatus="status">
						<c:if test="${status.index == 0}">
							<input type="radio" value="${kv.key }" name="genderCd" checked />${kv.value }	
			               </c:if>
						<c:if test="${status.index != 0}">
							<input type="radio" value="${kv.key }" name="genderCd" />${kv.value }	
			        	   </c:if>
					</c:forEach>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">出生日期</div>
				<div class="field">
					<input name="birthday" id="birthday" type="text"
						class="ui-datepicker" value="" validate="{required:true}">
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">手机号1</div>
				<div class="field">
					<input name="mp1" id="mp1" type="text" class="ui-textbox" value=""
						validate="{mobile:true,maxlength:20}">
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">手机号2</div>
				<div class="field">
					<input name="mp2" id="mp2" type="text" class="ui-textbox" value=""
						validate="{mobile:true,maxlength:20}">
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">办公电话</div>
				<div class="field">
					<input name="officeTel" id="officeTel" type="text"
						class="ui-textbox" value="" validate="{phone:true,maxlength:20}">
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">证件类型</div>
				<div class="field">
					<select name="certTypCd" id="certTypCd" data-value=""
						validate="{required:true, select: true}">
						<c:forEach items="${searchSelectCertTypCdList }" var="kv"
							begin="0" step="1" varStatus="status">
							<c:if test="${status.index == 0}">
								<option value="${kv.key }" checked>${kv.value }</option>
							</c:if>
							<c:if test="${status.index != 0}">
								<option value="${kv.key }">${kv.value }</option>
							</c:if>
						</c:forEach>
					</select> <span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">证件号</div>
				<div class="field">
					<input name="certNo" id="certNo" type="text" class="ui-textbox"
						value="" validate="{required:true, maxlength:30 }">
						<span class="requiredSymbol">*</span>
						<!-- <span class="addNpVerifyID" id="sCorpVerifyId">
		                    <a href="javascript:;" id="addCorpVerifyID" pass='n' class="liger_tip" title="未验证"><i class="sqIco sqIco_8"></i></a>
		                </span> -->
				</div>
			</div>
			<div class="fieldBox col_100">
				<div class="label">常住地址</div>
				<div class="field">
					<input name="homeAddr" id="homeAddr" type="text" class="ui-textbox"
						value="" validate="{maxlength:120}" placeholder="">
				</div>
			</div>
			<div class="fieldBox col_100">
				<div class="label">备注</div>
				<div class="field" style="width: 100%;">
					<textarea name="teamRem" id="teamRem" rows="4" class="l-textarea"
						style="width: 90%" validate="{maxlength:150}" placeholder=""></textarea>
				</div>
			</div>


			<div class="fieldBox col_100">
				<div class="sqPanel">
					<div class="sqPanel_head inL">
						<div class="btnsBox inLC">
							<span id="teamResumeAddBtn" class="sq-button sq-button-round"
								onclick="addTeamResumeRow();">添加</span> <span
								id="teamResumeDelBtn" class="sq-button sq-button-round"
								onclick="deleteTeamResumeRow();">删除</span>
						</div>
						<span>成员简历</span>
					</div>
					<div class="sqPanel_body">
						<div id="ligergrid_resume" class="sq-grid"></div>
					</div>
				</div>
			</div>


			<!-- hide data -->
			<div class="fieldBox col_100" style="display: none;">
				<div class="field">
					<input name=cstId id="cstId" type="text" class="ui-textbox"
						value="${cstId}"> <input name="ctId" id="ctId" type="text"
						class="ui-textbox" value="${ctId}">
				</div>
			</div>
		</div>
	</form>
	<script>
	
		$(function() {
			initForm();
			initEvent();
	        initData();
	        resumeGrid();
	        //npVerifyIDEvent();
		});
		
	    var resumeGrid;
	    var ligerPersonForm;
	    var checkFlag = 0;
		function resumeGrid(){
			 var ctId = $("#ctId").val();
			$("#ligergrid_resume").ligerGrid({
	            url: '<%=path%>/customer/cstcorpteamresume/initList.do?memId='+ctId,
	            method: 'get',
	            columns: [
	                {
	                	display: '开始时间', name: 'startDtStr', type: 'date', format: 'yyyy-MM-dd', 
	                	width: 100, editor: { type: 'date', format: 'yyyy-MM-dd'}
	                },{
	                    display: '结束时间', name: 'endDtStr', type: 'date', format: 'yyyy-MM-dd', 
	                    width: 100, editor: { type: 'date', format: 'yyyy-MM-dd'}
	                },
	                {
	                	display: '工作单位', name: 'workPlc',editor: { type: 'text' }
	                },
	                {
	                	display: '职务', name: 'post',editor: { type: 'text' }
	                }
	            ],
	            onBeforeEdit: function (e) {
	                //e.column.editor.data=typList;
	            },
	            onBeforeSubmitEdit: function (e) {
	                e.record[e.column.textField] = e.text
	            },
	            onCheckRow: function (checked,data,rowid,rowdata) {
	                //console.log(data);
	            },
	            usePager: false,
	            pageSize: 15,
	            root: 'rows',
	            record: 'total',
	            hideLoadButton: true,
	            width: '98%',
	            height: 300,
	            heightDiff: -2,
	            enabledEdit: true,
	            isScroll: false,
	            checkbox: true,
	            rownumbers: true,
	            allowUnSelectRow: true,
	            alternatingRow: false
	        });

	       resumeGrid = liger.get("ligergrid_resume");
		}
		
		//格式化时间
		function renderDate(rowdata, index, value){
			var dateStr = "";
			if(null != value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr;
		}
		
		 function addTeamResumeRow()
	     {
	            var row = resumeGrid.getSelectedRow();
	            //参数1:rowdata(非必填)
	            //参数2:插入的位置 Row Data 
	            //参数3:之前或者之后(非必填)
	            resumeGrid.addRow({ 
	            }, row, true);
	     } 
		 
		 //删除简历
		 function deleteTeamResumeRow()
	     { 	
			 $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
					if(flag == false)return;
			 		resumeGrid.deleteSelectedRow();
			 });
	     }
		
		//初始化表单
		function initForm(){
			ligerPersonForm = $("#cust_cst_corp_team_form").ligerForm({
                validate: true
           });
		}
		
		//初始化事件
		function initEvent(){
		}
		
		
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("cust_cst_corp_team_form");
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            /* if($("#addCorpVerifyID").attr("pass") == 'n'){
      			UIUtils.alertWarning("请验证身份证信息是否正确!");
    			return;
    		} */
    		npVerifyIDEvent();
            if(checkFlag == 1){
            	return;
            }
            var data = ligerForm.getData();
            
            var ctId = $("#ctId").val();
            var url = '<%=path%>/customer/cstcorpteam/add.do';
            if(ctId != ""){
            	url = '<%=path%>/customer/cstcorpteam/modify.do';
            	data["id"]= ctId;
            }
            //设置客户ID
            var cstId = $("#cstId").val();
            data["cstId"]= cstId;
            
            var wait_dialog=$.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });

            
            var resumeGridData = liger.get("ligergrid_resume").getData();
            data["resumeGrid"]= JSON.stringify(resumeGridData);
            
            $.ajax({
        		type: 'post',
        		dataType:'json',
        		data:data,
        		url: url,
        		success:function(msg){
        			 wait_dialog.close();
        			 if(msg.success == 1){
        				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
        				 parent.cstCorpTeamGrid.setParm("cstId",cstId);
        				 parent.cstCorpTeamGrid.reload();
        				 frameElement.dialog.close();
        			 }else{
        				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
        			 }
        		}
        	});
		}

		
		//初始化数据
		function initData(){
			var ctId = $("#ctId").val();
	    	if(!ctId)return;
	    	var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
	    	var _url = '<%=path%>/customer/cstcorpteam/getById.do';
	    	$.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{id:ctId},
	    		url: _url,
	    		success:function(msg){
	    			wait_dialog.close();
	    			 if(msg.success == 1){
	    				 setData(msg.data);//设置数据
	    			 }else{
	    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
    	}
		
		//设置页面数据
	    function setData(data){
	    	var form = new liger.get("cust_cst_corp_team_form");
	    	form.setData({
	    		mTypCd:data.mtypCd,
	    		mNm:data.mnm,
	    		mp1:data.mp1,
	    		mp2:data.mp2,
	    		certTypCd:data.certTypCd,
	    		certNo:data.certNo,
	    		/* certTypCd:data.certTypCd,
	    		certNo:data.certNo, */
	    		teamRem:data.teamRem,
	    		homeAddr:data.homeAddr,
	    		officeTel:data.officeTel
	    	});
	    	
	    	liger.get("certTypCd").setDisabled(true);
	    	if(StringUtils.isNotEmpty(data.certNo)){
	    		liger.get("certNo").setDisabled(true);
	    		liger.get("mNm").setDisabled(true);
	    		//$(".addNpVerifyID").closest(".addNpVerifyID").html(getCorpVerfiedIDHtmlPass());
	    	}
	    	
	    	if(data.birthday){
		    	var date = new Date(data.birthday);
	    		var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
	    		$("#birthday").val(dateStr);
	    	}else{
	    		$("#birthday").val("");
	    	}
    		//性别单独赋值
        	$("input[name='genderCd'][value="+data.genderCd+"]").prev(".l-radio").click();
		};
		
		//身份证第三方验证事件
	    function npVerifyIDEvent(){
	            var data = ligerPersonForm.getData();
	    		cstNm = data.mNm;//法定代表人名称
	    	    certNo = data.certNo;//法定代表人身份证号码
	            if(!cstNm){
	            	UIUtils.alertWarning("姓名不能为空");
	                return; //验证不通过，不执行以下代码
	            }
	            if(!certNo){
	            	UIUtils.alertWarning("身份证号不能为空");
	                return; //验证不通过，不执行以下代码
	            }
	            
	            $.ajax({
	           		type: 'post',
	           		dataType:'json',
	           		data:{cstNm:cstNm,certNo:certNo},
	           		url: '<%=path%>/customer/cstbscinfo/validateIdCard.do',
	           		success:function(msg){
	           			if(msg.success == 1){
	           				checkFlag = 0;
	           			 }else{//验证未通过
	                         UIUtils.alertWarning(msg.info);
	                         checkFlag = 1;
	           			 }
	           		}
	            });
	    };
	    
	    /* //验证身份证未通过-法人
	    function getCorpVerfiedIDHtmlNopass(){
	    	var html="<a href='javascript:;' id='addCorpVerifyID' pass='n' class='liger_tip' title='"+LogUtils.LOG_CMM_VALID_FAIL+"'><i class='sqIco sqIco_2'></i></a>";
	    	return html;
	    }
	    
	    //验证身份通过-法人
	    function getCorpVerfiedIDHtmlPass(){
	    	var html="<span class='liger_tip' id='addCorpVerifyID' pass='y' title='"+LogUtils.LOG_CMM_VALID_PASS+"'><i class='sqIco sqIco_1'></i></span>";
	    	return html;
	    }
	    
	    //身份未验证标记-法人
	    function getCorpVerfiedIDHtmlDefault(){
	    	var html = "<a href=\"javascript:;\" id=\"addCorpVerifyID\" pass='n' class=\"liger_tip\" title=\"未验证\"><i class=\"sqIco sqIco_8\"></i></a>";
	    	return html;
	    } */
	</script>
</body>
</html>